package com.ruoyi.product.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.product.domain.ProductFineManagement;
import com.ruoyi.product.service.IProductFineManagementService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 生产精细管理Controller
 * 
 * @author ruoyi
 * @date 2023-02-11
 */
@Controller
@RequestMapping("/product/fine")
public class ProductFineManagementController extends BaseController
{
    private String prefix = "product/fine";

    @Autowired
    private IProductFineManagementService productFineManagementService;

    @RequiresPermissions("product:fine:view")
    @GetMapping()
    public String fine()
    {
        return prefix + "/fine";
    }

    /**
     * 查询生产精细管理列表
     */
    @RequiresPermissions("product:fine:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ProductFineManagement productFineManagement)
    {
        startPage();
        List<ProductFineManagement> list = productFineManagementService.selectProductFineManagementList(productFineManagement);
        return getDataTable(list);
    }

    /**
     * 导出生产精细管理列表
     */
    @RequiresPermissions("product:fine:export")
    @Log(title = "生产精细管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ProductFineManagement productFineManagement)
    {
        List<ProductFineManagement> list = productFineManagementService.selectProductFineManagementList(productFineManagement);
        ExcelUtil<ProductFineManagement> util = new ExcelUtil<ProductFineManagement>(ProductFineManagement.class);
        return util.exportExcel(list, "生产精细管理数据");
    }

    /**
     * 新增生产精细管理
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存生产精细管理
     */
    @RequiresPermissions("product:fine:add")
    @Log(title = "生产精细管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ProductFineManagement productFineManagement)
    {
        return toAjax(productFineManagementService.insertProductFineManagement(productFineManagement));
    }

    /**
     * 修改生产精细管理
     */
    @RequiresPermissions("product:fine:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        ProductFineManagement productFineManagement = productFineManagementService.selectProductFineManagementById(id);
        mmap.put("productFineManagement", productFineManagement);
        return prefix + "/edit";
    }

    /**
     * 修改保存生产精细管理
     */
    @RequiresPermissions("product:fine:edit")
    @Log(title = "生产精细管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ProductFineManagement productFineManagement)
    {
        return toAjax(productFineManagementService.updateProductFineManagement(productFineManagement));
    }

    /**
     * 删除生产精细管理
     */
    @RequiresPermissions("product:fine:remove")
    @Log(title = "生产精细管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(productFineManagementService.deleteProductFineManagementByIds(ids));
    }
}
